<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>自定义对话框</title>
        <#include "/pubHeadStyle.html">
        <script src="${ctx}/extends/jquery.min.js" type="text/javascript"></script>
    </head>
    <body>
        <div class="ccpui-tablesize" style="padding:10px;">
            <table id="formDialog" lay-filter="formDialog"></table>
        </div>
        <script type="text/html" id="formDialogToolsBar">
            <div class="ccpui-enterSel">
                <div class="layui-btn-container">
                    <a class="layui-btn layui-btn-sm" lay-event="query">
                        <i class="layui-icon layui-icon-search"></i>
                        <span>查询</span>
                    </a>
                    <a class="layui-btn layui-btn-sm" lay-event="add">
                        <i class="layui-icon layui-icon-add-1"></i>
                        <span>添加</span>
                    </a>
                    <a class="layui-btn layui-btn-sm" lay-event="delete">
                        <i class="layui-icon layui-icon-delete"></i>
                        <span>刪除</span>
                    </a>
                    <a class="layui-btn layui-btn-sm" lay-event="combinationDialog">
                        <i class="layui-icon layui-icon-template-1"></i>
                        <span>组合对话框</span>
                    </a>
                    <a class="layui-btn layui-btn-sm" lay-event="reset">
                        <i class="layui-icon layui-icon-refresh"></i>
                        <span>重置</span>
                    </a>
                </div>
                <form class="layui-form" action="" style="margin-top:10px" lay-filter="formDialog_query">
                    <div class="table-top-filter">
                        <div class="table-filter-alone">
                            <label class="layui-form-label">名称 </label>
                            <input type="text" name="Q_name_SL" id="name" class="layui-input filter-value"
                                   placeholder="名称"
                                   autocomplete="off"/>
                        </div>
                        <div class="table-filter-alone">
                            <label class="layui-form-label">别名 </label>
                            <input type="text" name="Q_alias_SL" id="alias" class="layui-input filter-value"
                                   placeholder="别名"
                                   autocomplete="off"/>
                        </div>
                    </div>
                </form>
            </div>
        </script>

        <script type="text/html" id="manageBar">
            <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
            <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
            <a class="layui-btn layui-btn-xs" lay-event="preview">预览</a>
            <a class="layui-btn layui-btn-xs" lay-event="assist">开发帮助</a>
        </script>
        <script>
            var setter;
            var commons;
            layui.config({
                base: serverPath.formPath + staticPath.formPath //静态资源所在路径
            }).extend({
                index: 'index' //主入口模块
            }).use(['index', 'setter', 'commons', 'form', 'jquery', 'layer', 'common', 'table', 'totalFilter'], function () {
                var table = layui.table, layer = layui.layer, common = layui.common, totalFilter = layui.totalFilter;
                commons = layui.commons;
                setter = layui.setter;
                var tableH = commons.tabHeight();
                common.tableSort("formDialog");
                //渲染表格
                table.render({
                    elem: '#formDialog'
                    , cellMinWidth: 80
                    , title: '自定义对话框表'
                    , defaultToolbar: []
                    , height: tableH
                    , url: serverPath.formPath + setter.formLinkPath + 'formDialog/list'
                    , toolbar: '#formDialogToolsBar'
                    , page: true
                    , autoSort: false
                    , cols: [[
                        {type: 'checkbox', fixed: 'left'}
                        , {field: 'name', title: '名称', sort: true, align: 'center'}
                        , {field: 'alias', title: '别名', sort: true, align: 'center'}
                        , {
                            field: 'style', title: '显示样式', sort: true, align: 'center',
                            templet: function (d) {
                                if (d.style == 0) {
                                    return '<span style="color:green;">' + '列表' + '</span>';
                                }
                                return '<span style="color:red;">' + '树形' + '</span>';
                            }
                        }
                        , {
                            field: 'issingle', title: '是否单选', sort: true, align: 'center',
                            templet: function (d) {
                                if (d.issingle == 1) {
                                    return '<span style="color:green;">' + '单选' + '</span>';
                                }
                                return '<span style="color:red;">' + '多选' + '</span>';
                            }
                        }
                        , {field: 'width', title: '宽度', sort: true, align: 'center'}
                        , {field: 'height', title: '高度', sort: true, align: 'center'}
                        , {
                            field: 'istable', title: '是否为表', sort: true, align: 'center',
                            templet: function (d) {
                                if (d.istable == 1) {
                                    return '<span style="color:green;">' + '数据库表' + '</span>';
                                }
                                return '<span style="color:red;">' + '视图' + '</span>';
                            }
                        }
                        , {field: 'objname', title: '对象名称', align: 'center'}
                        , {field: 'dsname', title: '数据源名称', align: 'center'}
                        , {fixed: 'right', title: '管理', toolbar: '#manageBar', width: 200, align: 'center'}
                    ]],
                    done: function () {
                        common.tableSelectCon('.ccpui-enterSel .layui-form input', 'a[lay-event=query]', '.ccpui-enterSel')
                    }
                });
                totalFilter.init('formDialog');
                table.on('toolbar(formDialog)', function (obj) {
                    var checkStatus = table.checkStatus(obj.config.id);
                    var data = checkStatus.data; //获取选中行数据
                    switch (obj.event) {
                        case 'delete':
                            if (data.length === 0) {
                                layer.alert('请选择记录!');
                            } else {
                                layer.confirm('确认删除吗？', {
                                    btn: ['是', '否'] //按钮
                                }, function (index) {
                                    layer.close(index);
                                    var ids = [];
                                    for (var i = 0; i < data.length; i++) {
                                        ids.push(data[i].id);
                                    }
                                    var queryIds = ids.join(',');
                                    var t_date = {"ids": queryIds};
                                    $.ajax({
                                        url: serverPath.formPath + setter.formLinkPath + "formDialog/del",
                                        data: t_date,
                                        dataType: 'json',
                                        success: function (data) {
                                            layer.alert(data.msg);
                                            //执行重载
                                            table.reload('formDialog', {
                                                page: {
                                                    curr: 1
                                                }
                                            });
                                            totalFilter.init('formDialog');
                                        }
                                    });
                                });
                            }
                            break;
                        case 'query':
                            common.tableConditionRender("formDialog", "formDialog_query", {where: {}}, false);
                            break;
                        case 'add':
                            layer.open({
                                type: 2,
                                title: "添加自定义对话框",
                                shade: 0.3,
                                area: ['750px', '585px'],
                                content: serverPath.formPath + setter.formLinkPath + "formDialog/view/add"
                            });
                            break;
                        case 'combinationDialog':
                            var url = serverPath.formPath +"/form/formDialog/combinationDialog/view/list";
                            window.location.href = url;
                            break;
                        case 'reset':
                            common.tableConditionRender("formDialog", "formDialog_query", {where: {}}, true);
                            break;
                    }
                });
                //监听行工具事件
                table.on('tool(formDialog)', function (obj) {
                    switch (obj.event) {
                        case 'del':
                            layer.confirm('确认删除吗？', function (index) {
                                var selId = obj.data.id;
                                var t_date = {"ids": selId};
                                $.ajax({
                                    url: serverPath.formPath + setter.formLinkPath + "formDialog/del",
                                    data: t_date,
                                    dataType: 'json',
                                    success: function (data) {
                                        layer.alert(data.msg);
                                        //执行重载
                                        table.reload('formDialog', {
                                            page: {
                                                curr: 1
                                            }
                                        });
                                        totalFilter.init('formDialog');
                                    }
                                });
                            });
                            break;
                        case 'edit':
                            var formDialogId = obj.data.id;
                            layer.open({
                                type: 2,
                                title: "编辑",
                                shade: 0.3,
                                area: ['750px', '500px'],
                                content: serverPath.formPath + setter.formLinkPath + "formDialog/view/add?formDialogId=" + formDialogId
                            });
                            break;
                        case 'preview':
                            CommonDialog(obj.data.alias, function () {
                            }, "");
                            break;
                        case 'assist':
                            layer.open({
                                type: 2,
                                title: "开发帮助",
                                shade: 0.3,
                                area: ['700px', '500px'],
                                content: serverPath.formPath + setter.formLinkPath + "formDialog/view/assist"
                            });
                            break;
                    }
                });
            });

            /**
             * 通用对话框。
             * @param alias        对话框别名。
             * @param callBack    回调函数。
             * 调用示例：
             * CommonDialog("role",function(data){
             * });
             * data:为json数组或者为json对象。
             * @param paramValueString    向对话框传递的"参数=值"字符串
             * 传入多个则需要使用"&"符号进行连接（user=admin&orgId=1）
             */
            function CommonDialog(alias, callBack, paramValueString) {
                if (alias == null || alias == undefined) {
                    parent.layer.alert("别名为空！", '提示信息');
                    return;
                }
                $.ajax({
                    url: serverPath.formPath + setter.formLinkPath + "formDialog/dialogObj",
                    dataType: 'json',
                    type: "post",
                    data: {
                        "alias": alias
                    },
                    success: function (result) {
                        if (commons._filterRecord(result)) {
                            var obj = result.data;
                            var width = obj.width.toString() + "px";
                            var name = obj.name;
                            var height = obj.height.toString() + "px";
                            var displayList =  $.trim(obj.displayfield);
                            var resultfield =  $.trim(obj.resultfield);
                            if (displayList == "") {
                                parent.layer.alert("没有设置显示字段！", '提示信息');
                                return;
                            }
                            if (resultfield == "") {
                                parent.layer.alert("没有设置结果字段！", '提示信息');
                                return;
                            }
                            layer.open({
                                type: 2,
                                title: name,
                                shade: 0.3,
                                area: [width, height],
                                content: serverPath.formPath + setter.formLinkPath + "formDialog/view/show?alias=" + alias + "&dynamicPage=true&isOpenJsonData=true"
                            });
                        }
                    }
                });
            }
        </script>
    </body>
</html>
<link rel="stylesheet" href="${ctx}/css/font/iconfontie.css" media="all"/>
<link rel="stylesheet" href="${ctx}/iconfont/iconfont.css"/>